<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/WEB-INF/templates/BasicTemplate.xhtml">

	<ui:define name="content">
		<f:event type="preRenderView"
			listener="#{trainingController.beforeAdd}" />
		<div class="title ui-widget-header ui-corner-all">
			<h:panelGrid style="margin:auto;">
		AGREGAR CAPACITACIÓN
		</h:panelGrid>

		</div>
		<h:form id="formAdd">
			<h:panelGrid style="margin:auto;">

				<h:panelGrid style="margin:auto;text-align:center;">
					<p:messages id="messages"></p:messages>
				</h:panelGrid>

				<h:panelGrid columns="2" id="panelAdd">

					<h:panelGrid>
						<h:panelGrid columns="4">
							<p:outputLabel value="Documento de identidad"></p:outputLabel>
							<p:inputText id="candidateDocumentNumber"
								value="#{trainingController.candidateDocumentNumberSearch}"></p:inputText>
							<p:commandButton
								actionListener="#{trainingController.searchInterviewByDocumentNumber}"
								value="Buscar entrevistas"
								process="@this :formAdd:candidateDocumentNumber"
								update=":formAdd:interviewsTable :formAdd:interviewId :formAdd:messages">
							</p:commandButton>
							<p:outputLabel id="interviewId"
								value="Entrevista seleccionada: #{trainingController.interviewSelected!=null?trainingController.interviewSelected.id:''}">
							</p:outputLabel>
						</h:panelGrid>

						<p:dataTable value="#{trainingController.interviews}" var="i"
							rowKey="#{i.id}" id="interviewsTable" selectionMode="single"
							selection="#{trainingController.interviewSelected}">

							<p:ajax event="rowSelect" update=":formAdd:interviewId" />
							<p:ajax event="rowUnselect" update=":formAdd:interviewId" />

							<p:column headerText="ID">
								<h:outputText value="#{i.id}"></h:outputText>
							</p:column>

							<p:column headerText="DNI">
								<h:outputText value="#{i.candidate.documentNumber}"></h:outputText>
							</p:column>

							<p:column headerText="Nombres">
								<h:outputText value="#{i.candidate.firstname}"></h:outputText>
							</p:column>

							<p:column headerText="Apellidos">
								<h:outputText value="#{i.candidate.lastname}"></h:outputText>
							</p:column>

							<p:column headerText="Fecha de Entrevista">
								<h:outputText value="#{i.interviewedAt}">
									<f:convertDateTime pattern="dd-MM-yyyy" />
								</h:outputText>
							</p:column>

							<p:column headerText="Reclutador">
								<h:outputText
									value="#{i.recruiter.firstname} #{i.recruiter.lastname}"></h:outputText>
							</p:column>

							<p:column headerText="Estado">
								<h:outputText value="#{i.interviewState.name}"></h:outputText>
							</p:column>

							<p:column headerText="Comentarios">
								<h:outputText value="#{i.comment}"></h:outputText>
							</p:column>

						</p:dataTable>

					</h:panelGrid>
					<h:panelGrid columns="2">



						<p:outputLabel value="Fecha de Capacitación"></p:outputLabel>
						<p:calendar
							value="#{trainingController.trainingSelected.trainingAt}"
							pattern="dd-MM-yyyy" required="true"
							requiredMessage="Debe seleccionar fecha de capacitación">
						</p:calendar>

						<p:outputLabel value="Capacitador"></p:outputLabel>
						<p:selectOneMenu id="trainers" required="true"
							requiredMessage="Debe seleccionar capacitador"
							value="#{trainingController.trainerSelected}">
							<f:selectItem itemValue="" itemLabel="Seleccione.."></f:selectItem>
							<f:selectItems value="#{trainingController.trainers}"></f:selectItems>
						</p:selectOneMenu>

						<p:outputLabel value="Comentarios:"></p:outputLabel>
						<p:inputTextarea
							value="#{trainingController.trainingSelected.comment}" rows="4"
							cols="30"></p:inputTextarea>

					</h:panelGrid>

				</h:panelGrid>

				<h:panelGrid style="margin:auto;text-align:center;">
					<p:commandButton action="#{trainingController.add}" value="Agregar"
						ajax="false">
					</p:commandButton>
				</h:panelGrid>
			</h:panelGrid>
		</h:form>
	</ui:define>

</ui:composition>
</html>
